/**
 * 
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 *   
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 * 
 */
package org.jiopi.module.mailsender;

import org.jiopi.blueprint.mailsender.Mail;
import org.jiopi.blueprint.mailsender.MailSender;
import org.jiopi.blueprint.mailsender.SendMailException;
import org.jiopi.framework.annotation.module.Instantiation;
import org.jiopi.framework.annotation.module.InstanceType;
import org.jiopi.framework.annotation.module.RegisterModule;

@RegisterModule
@Instantiation(type=InstanceType.CONFIGURATION_SINGLETON)
public class MailSenderImpl implements MailSender {
	
	private String hostname;
	private String username;
	private String password;
	private String charset;
	private String from;
	private String smtpport;
	
	

	public Mail createNewHtmlMail() {
		MailImpl mail = new MailImpl();
		mail.mailSender = this;
		mail.changeMailType(Mail.HTML_MAIL);
		return mail;
	}

	public Mail createNewTextMail() {
		MailImpl mail = new MailImpl();
		mail.mailSender = this;
		mail.changeMailType(Mail.TEXT_MAIL);
		return mail;
	}

	public String sendMail(String to,String subject,String message) throws SendMailException{
		Mail mail = createNewTextMail();
		mail.addTo(to);
		mail.setSubject(subject);
		mail.setTextMsg(message);
		return mail.send();

	}
    public String sendMail(String to,String subject,String html,String text) throws SendMailException{
    	Mail mail = createNewHtmlMail();
		mail.addTo(to);
		mail.setSubject(subject);
		mail.setHtmlMsg(html);
		mail.setTextMsg(text);
		return mail.send();
	}

	public String getAuthenticationPassword() {
		return this.password;
	}

	public String getAuthenticationUserName() {
		return this.username;
	}

	public String getHostName() {
		return this.hostname;
	}

	public String getCharset() {
		return this.charset;
	}

	public String getFrom() {
		return this.from;
	}
	
	public void setUsername(String username){
		this.username = username;
	}
	
	public void setPassword(String password){
		this.password = password;
	}
	public void setHostname(String hostname){
		this.hostname = hostname;
	}
	
	public void setCharset(String charset) {
		this.charset = charset;
	}

	public void setFrom(String from) {
		this.from = from;
	}

	public String getSmtpport() {
		return smtpport;
	}

	public void setSmtpport(String smtpport) {
		this.smtpport = smtpport;
	}

}
